package algotithm.leetcode.dfs.test78;

import java.util.*;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/8-16:06
 */
public class Solution {
    public static void main(String[] args) {
        Solution t = new Solution();
        int[] arr = {1,2,3};
        Arrays.sort(arr);
        List<List<Integer>> list = t.subsets(arr);
        System.out.println(list);
    }

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> list = new ArrayList<>();
        if (nums.length == 0) {
            return new ArrayList<>(0);
        }
        Deque<Integer> path = new ArrayDeque<>();
        int len = nums.length;
        dfs(nums,0,len,path,list);
        return list;
    }

    public void dfs(int[] nums, int begin, int len, Deque<Integer> path, List<List<Integer>> list) {
        list.add(new ArrayList<>(path));
        System.out.println("path 为 ： "  + list);
        for (int i = begin; i < len; i++) {
            path.addLast(nums[i]);
            dfs(nums,i+1,len,path,list);
//            System.out.println("回溯之前是：" + path);
            path.removeLast();
//            System.out.println("回溯之后是: " + path);
        }

    }
}